﻿package {
	import flash.display.*;
	import flash.geom.ColorTransform;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import flash.utils.Timer;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;

	public dynamic class Main extends MovieClip {

		private var _root:Sprite;
		private var llkBackground:llkBG;
		private var starter:Starter;
		private var llkGame:Game;
		private var startmp3:startMP3;
		private var loading:TextField;

		private function frameScript():void {
			//trace("第二帧停止");
			stop();
			//操作   
			removeChild(loading);
			removeChild(bg);
			llkBackground=new llkBG();
			_root.addChild(llkBackground);
			startmp3=new startMP3;
			startmp3.play();
			starter=new Starter(startgame);
			_root.addChild(starter);
			llkGame=new Game();
			//startgame();
		}



		public function Main():void {
			_root=new MovieClip();
			addChild(_root);
			loading=new TextField();
			loading.y=150;
			loading.autoSize=TextFieldAutoSize.LEFT;
			loading.selectable=false;
			loading.textColor=0xCCCCCC;
			addChild(loading);
			this.addEventListener(Event.ADDED_TO_STAGE,added);
			//width=700;
			addFrameScript(1,frameScript);

			//_root.addEventListener(MouseEvent.MOUSE_MOVE,onmove);
		}
		private function added(e:Event):void {
			this.loaderInfo.addEventListener(ProgressEvent.PROGRESS,loadProgress);
			this.loaderInfo.addEventListener(Event.COMPLETE,loadComplete);
		}
		private function loadProgress(e:ProgressEvent):void {
			//trace(e.bytesLoaded);
			var percent:Number=e.bytesLoaded*100/e.bytesTotal;
			loading.text=percent.toFixed()+"%";
			loading.x=(550-loading.width)/2;
		}
		private function loadComplete(e:Event):void {
			gotoAndStop(2);
		}
		private function onmove(e:MouseEvent):void {
			//trace(_root.mouseX,_root.mouseY);
		}
		private function startgame(e:MouseEvent=null):void {
			_root.removeChild(starter);
			//_root.addChild(starter);
			_root.addChild(llkGame);
			llkGame.start();
		}
	}
}